Factory Server
In this example the Factory Server simulates a service factory (which
is also a manager too). The interface design follows the object factory
pattern. This example demonstrates how to:
-
Design interfaces using the object factory pattern
-
Implement interfaces using the TIE mechanism
-
Manage CORBA objects with a hash table
Source Files
-
factory.idl
IDL file for the interfaces Service and ServiceFactory in the factory
module. Also defined are exceptions "ServiceError" and "FactoryError".
-
Server.java
The Server code, which has a main function that creates an instance
of the ServiceFactoryImpl class and calls obj_is_ready()and
impl_is_ready() to make it available to the client.
The code contains the following interface implementation classes:
-
ServiceFactoryImpl
A generic implementation for the interface "ServiceFactory". The create
method is not implemented here. It is left to the subclass URLServerFactoryImpl.
This implementation also include some mangement methods: find, remove,
and showAll.
-
ServiceImpl
A generic implementation for the interface "Service". It
implements the method getName but not performService.
-
URLServiceFactoryImpl
A specific implementation for the interface "ServiceFactory" and a
subclass of ServiceFactoryImpl. It implements the create
method, which is characteristic of object factories. The create
method creates a new ServerImpl object with a unique name.
-
URLServiceImpl
A specific implementation for the interface "Service" and a subclass
of ServiceImpl. It implements the method performService
to retrieve the contents of an URL.
-
Client.java
The client code. It binds to the URLServiceFactoryImpl
object using a factory server name (e.g. "URL Service Factory").
It then waits for user commands to create and perform services. The
runTerminal method translates command line inputs into method calls to
the server. One may also run the client with an input text file that
contains multiple command lines. An example is in Test1.txt.
Batch Files
-
build.bat
A batch file for building the client and server on Windows.
It will first invoke the IDL compiler and then compile the server and client
source codes. A subdirectory named "factory" will be created, which
contains the CORBA stub and skeleton codes and their corresponding class
files.
-
runsrv.bat
A batch file for running the server.
-
client.bat
A batch file for running the client. The command line format
is:
client [hostname] [command.txt]
where the optional hostname (or IP address) is where the server is running
and command.txt is an optional input command file such as Test1.txt.
Running the Codes
This example was developed under VisiBroker (link).
To run the codes, make sure that the VisiBroker Smart Agent (osagent) is
running on your network. Then enter the commands:
On Windows:
start runsrv
client (or client [hostname] [Test1.txt])
On Unix:
vbj Server &
vbj Client (or vbj Client [hostname] [Test1.txt])